package com.example.dell.workactivity.mvp;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.example.dell.basic.AppComplication;
import com.example.dell.basic.BasicBasicActivity;
import com.example.dell.basicapplication.R;
import com.example.dell.network.http.HttpManager;
import com.example.dell.network.http.RequestBodyUtils;
import com.example.dell.network.http.CallBack;
import com.example.dell.network.okgonet.OkUtil;
import com.example.dell.network.okgonet.OkgoCallBack;
import com.example.dell.utils.Utils;
import com.lzy.okgo.model.Response;

import java.util.HashMap;

import okhttp3.RequestBody;

public class LoginActivity extends BasicBasicActivity {


    private TextView mJsonText;

    @Override
    protected int setContentSuccessView() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView(View view) {
        showAction(false, 0);
        getBasicBar().setVisibility(View.GONE);
        mJsonText = (TextView) view.findViewById(R.id.json_text);
        autoShowPager(true, "");
    }

    @Override
    protected void initData() {

    }

    //普通登录
    public void normalClick(View view) {
        String url = "http://api.932edu.com/courseSys/app/login/login";
        String psw = "qwq";
        try {
            psw = Utils.md5Encode("000000");
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBodyUtils.getLoginRequestBody("18221884661", psw);
        HttpManager.getInstance().post(url, new CallBack() {
            @Override
            public void onSuccess(String t) {
                if (t != null) {
                    mJsonText.setText(t + "");
                }
            }

            @Override
            public void onFailure(String message, int error) {
                if (message != null) {
                    mJsonText.setText(message);
                }
            }
        }, body);
    }

    public void retorfitlClick(View view) {
        HashMap<String, String> map = new HashMap<>();
        map.put("phone", "18221884661");
        map.put("password", "000000");
        String url = "http://api.932edu.com/courseSys/app/login/login";
        OkUtil.postRequest(url, map, new OkgoCallBack<String>() {
            @Override
            public void onSuccess(Response<String> t) {

                System.out.println("当前数的数据是"+t.body());
            }

            @Override
            public void onFailure(String message, int error) {
                System.out.println("失败");
            }

            @Override
            public void onNetError() {

            }

        });
//        OkUtil.postRequest(url, map, new JsonCallback<String>() {
//            @Override
//            public void onSuccess(Response<String> response) {
//                System.out.println("当前数的数据是"+response.body());
//            }
//        });

    }

    public void dayAndnignt(View view) {

        AppComplication.updateNightMode(true);
        finish();
        startActivity(new Intent( this, this.getClass()));
        overridePendingTransition(0, 0);
    }
}
